/**
 * 
 */
package com.nightsoul.groovy



/**
 * @author zj
 *
 */
public class ClosureScope{
	
	static void main(String[] args) {
		Mother julia = new Mother();

		def closure = julia.birth(4);
		println closure.owner
		def context = closure.call(this);
		println context[0].class.name;
		println context[1..4]
		println context[5]
//		println context[6]

		def firstClosure = julia.birth(4);
		def secondClosure = julia.birth(4);
		println firstClosure.is(secondClosure);
		
	}
	
	
}


class Mother {
	int field = 1;
	int foo() {
		return 2;
	}

	Closure birth(param) {
		def local = 3;
		def closure = {caller ->
			// this variable is instance of Mother, not Closure
			[this, field, foo(), local, param, caller]
		}
		return closure;
	}
}